using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Hotran.SaveSystem;

public class JointSaver : MonoBehaviour, ISavable
{
    private struct SaveData
    {
        public Rigidbody2D connected;
    }

    private FixedJoint2D _fixedJoint;


    private void Awake()
    {
        _fixedJoint = GetComponent<FixedJoint2D>();
    }

    public object Save()
    {
        return new SaveData()
        {
            connected = _fixedJoint.connectedBody
        };
    }

    public void Load(object data)
    {
        SaveData saveData = (SaveData)data;
        _fixedJoint.connectedBody = saveData.connected;
        if (saveData.connected != null)
        {
            _fixedJoint.enabled = true;
        }
        else
            _fixedJoint.enabled = false;
    }
}
